/*
 * Copyright 2014 Niek Haarman
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.lab.adapter.animation;

import android.support.annotation.NonNull;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.lab.utils.DisplayUtil;
import com.nineoldandroids.animation.Animator;
import com.nineoldandroids.animation.ObjectAnimator;

/**
 * An implementation of the AnimationAdapter class which applies a
 * swing-in-from-bottom-animation to views.
 */
public class SwingBottomInAnimationAdapter extends AnimationAdapter {

    private static final String TRANSLATION_Y = "translationY";
    private static final String ALPHA = "alpha";

    public SwingBottomInAnimationAdapter(@NonNull final BaseAdapter baseAdapter) {
        super(baseAdapter);
    }

    @NonNull
    @Override
    public Animator[] getAnimators(@NonNull ViewGroup parent, @NonNull View view) {
        Animator[] animators = new Animator[2];
        //view.getMeasuredHeight() 如果还未绘制的时候会返回0，导致动画不会做，所以取了个300dp作为动画起始点
        animators[0] = ObjectAnimator.ofFloat(view, TRANSLATION_Y, DisplayUtil.dip2px(300), 0);
        animators[1] = ObjectAnimator.ofFloat(view, ALPHA, 0, 1);
        return animators;
    }

}
